//
//  Path.m
//  SmileRead
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "Path.h"
#import "UIImageView+WebCache.h"



@implementation Path

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

// 获取图片的路径
+ (NSString *)pathOfImageWithName:(NSString *)name
{
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
    return path;
}


// 获取Library下的文件路径
+ (NSString *)pathOfLibraryWithFileName:(NSString *)fileName
{
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *path = [NSString stringWithFormat:@"%@/%@", [array firstObject], fileName];
    return path;
}

// 由第三方SDWebImage获得照片

+ (void)pathWithImageView:(UIImageView *)imageView URLString:(NSString *)UrlStr
{
    NSURL *url = [NSURL URLWithString:UrlStr];
    //[imageView sd_setImageWithURL:url];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"p" ofType:@"jpg"];
    
    [imageView sd_setImageWithURL:url placeholderImage:[UIImage imageWithContentsOfFile:path]];
}

// 颜色调色剂
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue
{
    UIColor *color = [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1];
    return color;
}

// 高亮设置
+ (NSAttributedString *)lightWithTitle:(NSString *)title text:(NSString *)text
{
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:title];
    
    for (int i = 0; i < title.length - text.length + 1; i++) {
        
        if ([[title substringWithRange:NSMakeRange(i, text.length)] isEqualToString:text]) {
            NSRange range = NSMakeRange(i, text.length);
            [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
        }
    }
    return attStr;
}

// tableViewCell的separatorStyle的设置

+ (void)separatorStyleWithTableview:(UITableView *)tableView array:(NSArray *)array
{
    if (array.count == 0) {
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    else {
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
}



@end
